package com.tn.controller.basic;

import com.gitee.hifong45.Ret;
import com.tn.controller.alarm.common.model.CommonVO;
import com.tn.controller.alarm.common.model.basic.vo.KeyBasicDataVO;
import com.tn.exception.DatabaseOperationFailedException;
import com.tn.exception.InvalidParamException;
import com.tn.service.basic.IBasicDataService;
import com.tn.utils.CheckParamUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 货品，物流公司，货主单位管理
 *
 * @program: tn_aucy_java
 * @author: yangjiayao
 * @create: 2022/1/7
 */
@Slf4j
@RestController
@RequestMapping("/aucy/basicData")
public class BasicDataController {

    //@Resource
    private IBasicDataService basicDataService;

    @Autowired
    public void setIBasicDataService(IBasicDataService basicDataService) {
        this.basicDataService = basicDataService;
    }

    /**
     * 新增货品，物流公司，货主单位
     *
     * @param basicDataVO 摄像头信息
     * @return 新增结果
     * @throws DatabaseOperationFailedException 数据库操作异常
     * @throws InvalidParamException            参数异常
     */
    @PostMapping(value = "/addBasicData" , produces = {"application/json;charset=UTF-8"})
    public Ret<Object> addBasicData(@RequestBody KeyBasicDataVO basicDataVO)
            throws DatabaseOperationFailedException, InvalidParamException {
        CheckParamUtil.checkNullRequiredParam(basicDataVO.getKeyCode());
        CheckParamUtil.checkBasicDataRequiredParam(basicDataVO,"add");
        return Ret.Ok(basicDataService.addBasicData(basicDataVO));
    }

    /**
     * 修改货品，物流公司，货主单位
     *
     * @param basicDataVO 摄像头信息
     * @return 修改结果
     * @throws DatabaseOperationFailedException 数据库操作异常
     * @throws InvalidParamException            参数异常
     */
    @PostMapping(value="/modifyBasicData" ,produces = {"application/json;charset=UTF-8"})
    public Ret<Object> modifyBasicData(@RequestBody KeyBasicDataVO basicDataVO)
            throws DatabaseOperationFailedException, InvalidParamException {
        CheckParamUtil.checkNullRequiredParam(basicDataVO.getId());
        CheckParamUtil.checkBasicDataRequiredParam(basicDataVO,"modify");
        basicDataService.modifyBasicData(basicDataVO);
        return Ret.Ok();
    }

    /**
     * 删除货品，物流公司，货主单位
     *
     * @param basicDataVO 摄像头信息
     * @return 删除结果
     * @throws DatabaseOperationFailedException 数据库操作异常
     * @throws InvalidParamException            参数异常
     */
    @RequestMapping("/deleteBasicData")
    public Ret<Object> deleteBasicData(@RequestBody KeyBasicDataVO basicDataVO)
            throws DatabaseOperationFailedException, InvalidParamException {
        CheckParamUtil.checkNullRequiredParam(basicDataVO.getId());
        basicDataService.deleteBasicData(basicDataVO);
        return Ret.Ok();
    }


    /**
     * 删除货品，物流公司，货主单位
     *
     * @param basicDataVO 摄像头信息
     * @return 删除结果
     * @throws DatabaseOperationFailedException 数据库操作异常
     * @throws InvalidParamException            参数异常
     */
    @RequestMapping("/batchDelete")
    public Ret<Object> batchDelete(@RequestBody KeyBasicDataVO basicDataVO)
            throws DatabaseOperationFailedException, InvalidParamException {
        CheckParamUtil.checkNullRequiredParam(basicDataVO.getIds());
        basicDataService.deleteBasicData(basicDataVO);
        return Ret.Ok();
    }
 /*   *//**
     * 导入
     * @param file
     * @return
     * @throws Exception
     *//*

    @PostMapping(value ="/importData",produces = {"application/json;charset=UTF-8"})
    public Ret<String> importData(@PathParam("file") MultipartFile file,@PathParam("kind")String kind)
    {
        String msg = basicDataService.importExcel(file,kind);
        if(msg.contains("success")){
           return Ret.Ok(msg);
        } else{
            return Ret.Fail(500,msg);
        }
    }*/


    /**
     * 查询货品信息
     *
     * @param dataVO 分页查询条件
     * @return 查询结果
     * @throws InvalidParamException 参数异常
     */
    @RequestMapping("/queryBasic")
    public CommonVO<List<KeyBasicDataVO>> queryBasic(@RequestBody KeyBasicDataVO dataVO)
            throws InvalidParamException {
        CommonVO<List<KeyBasicDataVO>> result = new CommonVO<>();
        result.setData(basicDataService.queryList(dataVO));
        result.setCode(200);
        return result;
    }

    /**
     * 查询货品信息
     *
     * @param basicDataVO 分页查询条件
     * @return 查询结果
     * @throws InvalidParamException 参数异常
     */
    @PostMapping(value ="/queryKeyList",produces = {"application/json;charset=UTF-8"})
    public Ret<List<KeyBasicDataVO>> queryKeyList(@RequestBody KeyBasicDataVO basicDataVO) {
        return Ret.Ok(basicDataService.queryList(basicDataVO));
    }

}
